package com.ssh;

import org.junit.Test;

public class MaxSubArray_53 {
	@Test
	public void test () {
		int[] a = {-2,1,-3,4,-1,2,1,-5,4};
		System.out.println(maxSubArray(a));
	}
	
	public int maxSubArray(int[] nums) {
        int n = nums.length;
        int[] d = new int[n];
        d[0] = nums[0];
        int max = d[0];
        for (int i = 1; i < n; i++) {
        	d[i] = nums[i] + ((d[i - 1] > 0) ? d[i - 1] : 0);
        	max = Math.max(max, d[i]);
        }
        return max;
    }
}
